import pandas as pd
import re

df = pd.read_csv('./demo.csv')


def find_dates(text):
    arr = re.findall(r"(\d{4}-\d{1,2}-\d{1,2})", text)
    return '#'.join(arr)


df['dates'] = df['f8'].apply(lambda x: find_dates(x))
df['start_date'] = df['dates'].apply(lambda x: x.split('#', 1)[0])
df['end_date'] = df['dates'].apply(lambda x: x.split('#', 1)[1])
df['id'] = df['f1']
df.drop(columns=['f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'dates'], inplace=True)
df
df.to_csv('result.csv')
